<?php

/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

namespace EasyActionPHP\Controller;

/**
 * ActionForwardMapping.
 *
 * @author Flavio de Vasconcellos Correa
 * @since 2007/06/04
 * @package EasyActionPHP
 * @subpackage Controller
 * @version $id$
 * @license http://www.gnu.org/copyleft/gpl.html GPL
 */
class ActionForwardMapping {

    /**
     * @var Array[ActionForward] Lista de forwards associados a um AbstractAction like.
     */
    var $forwards;

    /**
     * Construtor.
     */
    function __construct() {
        $this->forwards = Array();
    }

    /**
     * Adiciona uma instancia de ActionForward.
     *
     * @param ActionForward forward
     * @return void
     */
    public function add(ActionForward $forward) {
        $this->forwards[$forward->name] = $forward;
    }

    /**
     * Retorna a lista de instancias de ActionForward armazenadas.
     *
     * @access public
     * @return Array[ActionForward]
     */
    public function getForwards() {
        return $this->forwards;
    }

    /**
     * Retorna uma instancia de ActionForward.
     *
     * @access public
     * @param String name.
     * @return ActionForward
     */
    public function findForward($name = false) {
        if (!$name)
            return $this->getDefaultForward();
        if (array_key_exists($name, $this->forwards)) {
            return $this->forwards[$name];
        } else {
            $forward = ActionController::getGlobalForward($name);
            return $forward;
        }
    }

}

?>